package com.sugou.dao.support.ext.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.sugou.dao.support.ParamsStatement;
import com.sugou.dao.support.Statement;
import com.sugou.dao.support.ext.Columns;

public class ColumnsImpl implements Columns {
	private static final long serialVersionUID = 359071157852065625L;
	
	private Statement body;
	
	private String alias;
	
	public ColumnsImpl(Statement body,String alias) {
		this.body=body;
		this.alias=alias;
	}

	public String getContent() {
		StringBuilder hql=new StringBuilder(this.body.getContent());
		if(StringUtils.isNotBlank(this.alias)){
			hql.append(" as ").append(this.alias);
		}
		return hql.toString();
	}
	
	public Statement getBody() {
		return this.body;
	}

	public String getAlias() {
		return this.alias;
	}

	public List<? extends Serializable> getParams() {
		if(this.body instanceof ParamsStatement){
			return new ArrayList<Serializable>(((ParamsStatement) this.body).getParams());
		}
		return new ArrayList<Serializable>();
	}
}
